package com.hxzy.projectssmplus.controller;


import com.hxzy.projectssmplus.entity.HouseSupport;
import com.hxzy.projectssmplus.service.HouseSupportService;
import com.hxzy.projectssmplus.vo.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class HouseSupportController {
    @Autowired
    private HouseSupportService houseSupportService;

    @GetMapping(value = "/support/one/{houseId}")
    public AjaxResult supportOne(@PathVariable(value = "houseId") Long houseId){

        HouseSupport houseSupport = this.houseSupportService.supportOne(houseId);

        if(houseSupport==null){
            houseSupport=new HouseSupport();
        }
        return AjaxResult.success_data(houseSupport);
    }

    @GetMapping(value = "support/updata")
    public AjaxResult supportUpdata(HouseSupport houseSupport){
        System.out.println("support获取的修改的数据的id    "+houseSupport.getId());
        Integer integer = this.houseSupportService.supportUpdata(houseSupport);
        return integer>0?AjaxResult.success("support修改成功"):AjaxResult.error("support修改数据失败");
    }

    @PostMapping(value = "support/add")
    public AjaxResult supportAdd(@RequestBody HouseSupport houseSupport){
        Integer integer = this.houseSupportService.supportAdd(houseSupport);
        return integer>0?AjaxResult.success("support新增成功"):AjaxResult.error("support新增失败");
    }
}
